package days25.title14;




import org.junit.Test;

import javax.lang.model.SourceVersion;

/**
 * @Author fengzihao
 * @Date 2024-05-09 19:56
 */
class Solution {
    // @Test
    // public void test1(){
    //     String[] strings = {"flower","flow","flight"};
    //     System.out.println("strings = " + longestCommonPrefix(strings));
    // }
    public String longestCommonPrefix(String[] strs) {
        String str = "";
        if (strs.length==1)
            return strs[0];
        for (int i = 0; i < strs[0].length(); i++) {
            int flag = 0;
            if (strs[0].length()==0)
                return "";
            char ch = strs[0].charAt(i);
            for (int j = 0; j <strs.length; j++) {
                if (strs[j].length()<i+1){
                    flag = 1;
                    break;
                }
                if (ch!=strs[j].charAt(i)){
                    flag = 1;
                    break;
                }
            }
            if (flag == 1)
                break;
            str=str+ch;
        }
        return str;
    }
}